/*
 * Copyright (C) 2008-2011 CBDP Consortium
 * 
 * All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.
 * 
 * This software consists of contributions made by many individuals, 
 * listed below:
 *
 * Author: 	Xabier Laiseca <xabier.laiseca@deusto.es>
 * 			David Ausín <david.ausin@deusto.es>
 */
package cbdp.server.contextreasoner.impl.contextmanager.online.model.wrappers;

import cbdp.server.contextreasoner.internal.InternalContextManager;
import cbdp.server.contextreasoner.model.GenericProperty;
import cbdp.server.contextreasoner.model.exceptions.PreviouslyDeteledPropertyException;

public class EagerSavingGenericPropertyRuleLaunchingWrapper<T extends GenericProperty> implements GenericProperty
{
	protected T wrapped;
	
	protected InternalContextManager contextManager;
	
	public void setGenericProperty(final T wrapped)
	{
		this.wrapped = wrapped;
	}
	
	public void setInternalContextManager(final InternalContextManager contextManager)
	{
		this.contextManager = contextManager;
	}

	@Override
	public void delete() throws PreviouslyDeteledPropertyException
	{
		wrapped.delete();
		launchRulesIfNotInExecution();
	}
	
	protected void launchRulesIfNotInExecution()
	{
		if (!contextManager.isInExecution())
		{
			contextManager.getGenericReasoner().launchRuleSets();
		}
	}
}
